package com.tmc.entity.inthotel;

import java.util.List;
import java.util.Set;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * A data access object (DAO) providing persistence and search support for
 * ToHotel entities. Transaction control of the save(), update() and delete()
 * operations can directly support Spring container-managed transactions or they
 * can be augmented to handle user-managed Spring transactions. Each of these
 * methods provides additional information for how to configure it for the
 * desired type of transaction control.
 * 
 * @see entity.ToHotel
 * @author MyEclipse Persistence Tools
 */

public class ToHotelDAO extends BaseHibernateDAO {
	private static final Logger log = LoggerFactory.getLogger(ToHotelDAO.class);
	// property constants
	public static final String HOTEL_NAME = "hotelName";
	public static final String DESTINATION_ID = "destinationId";
	public static final String HOTEL_LATITUDE = "hotelLatitude";
	public static final String HOTEL_LONGITUDE = "hotelLongitude";
	public static final String ADDRESS = "address";
	public static final String ZIP = "zip";
	public static final String CITY = "city";
	public static final String LOCATION = "location";
	public static final String STATE = "state";
	public static final String STATE_CODE = "stateCode";
	public static final String COUNTRY_CODE = "countryCode";
	public static final String DESTINATION_CODE = "destinationCode";
	public static final String STARS = "stars";
	public static final String STATUS = "status";
	public static final String UPLOADED = "uploaded";

	public void save(ToHotel transientInstance) {
		log.debug("saving ToHotel instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(ToHotel persistentInstance) {
		log.debug("deleting ToHotel instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public ToHotel findById(java.lang.Integer id) {
		log.debug("getting ToHotel instance with id: " + id);
		try {
			ToHotel instance = (ToHotel) getSession().get("entity.ToHotel", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(ToHotel instance) {
		log.debug("finding ToHotel instance by example");
		try {
			List results = getSession().createCriteria("entity.ToHotel").add(
					Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding ToHotel instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from ToHotel as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByHotelName(Object hotelName) {
		return findByProperty(HOTEL_NAME, hotelName);
	}

	public List findByDestinationId(Object destinationId) {
		return findByProperty(DESTINATION_ID, destinationId);
	}

	public List findByHotelLatitude(Object hotelLatitude) {
		return findByProperty(HOTEL_LATITUDE, hotelLatitude);
	}

	public List findByHotelLongitude(Object hotelLongitude) {
		return findByProperty(HOTEL_LONGITUDE, hotelLongitude);
	}

	public List findByAddress(Object address) {
		return findByProperty(ADDRESS, address);
	}

	public List findByZip(Object zip) {
		return findByProperty(ZIP, zip);
	}

	public List findByCity(Object city) {
		return findByProperty(CITY, city);
	}

	public List findByLocation(Object location) {
		return findByProperty(LOCATION, location);
	}

	public List findByState(Object state) {
		return findByProperty(STATE, state);
	}

	public List findByStateCode(Object stateCode) {
		return findByProperty(STATE_CODE, stateCode);
	}

	public List findByCountryCode(Object countryCode) {
		return findByProperty(COUNTRY_CODE, countryCode);
	}

	public List findByDestinationCode(Object destinationCode) {
		return findByProperty(DESTINATION_CODE, destinationCode);
	}

	public List findByStars(Object stars) {
		return findByProperty(STARS, stars);
	}

	public List findByStatus(Object status) {
		return findByProperty(STATUS, status);
	}

	public List findByUploaded(Object uploaded) {
		return findByProperty(UPLOADED, uploaded);
	}

	public List findAll() {
		log.debug("finding all ToHotel instances");
		try {
			String queryString = "from ToHotel";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public ToHotel merge(ToHotel detachedInstance) {
		log.debug("merging ToHotel instance");
		try {
			ToHotel result = (ToHotel) getSession().merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(ToHotel instance) {
		log.debug("attaching dirty ToHotel instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(ToHotel instance) {
		log.debug("attaching clean ToHotel instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}